/** \file    imagine.h
  * \brief   Representation functions of different 2d objects
  * \date    2001
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/include/imglib/imagine.h,v 1.2 2006/01/16 15:46:13 cscom1r4 Exp $
  */

#ifndef _imagine_h_
#define _imagine_h_

#include "imglib/imageclass_decl.h"
#include "imglib/color.h"
#include "imglib/boundmap.h"

namespace img {

const byte_color byte_white = byte_color(255,255,255,255);

///blends/replaces with a given color not masked pixels
void emphasizeMask(byte_image &img, const img::bitmap &bmp, bool blend = true,
				  const byte_color &color = byte_white);
///the same for multi-valued mask stored in alpha channel
void emphasizeMask(byte_image &img, bool blend = true,
				  const byte_color &color = byte_white);

///enlarges raster and draws bounds in it
template <class raster>
void imagine_boundmap( 
	raster &imagination,	///< output
	const raster &bgrd,		///< input background
	const boundmap &bounds,	///< source of bounds
	const typename raster::elem_type &bound_color 
		= raster::elem_type() ); ///< color to draw the bounds

//////////////////////////
// template definitions //
//////////////////////////

template <class raster>
void imagine_boundmap( 
	raster &imagination, const raster &bgrd,
	const boundmap &bounds,
	const typename raster::elem_type &bound_color )
{
	int x_enlargement = imagination.width() / bgrd.width();
	int y_enlargement = imagination.height() / bgrd.height();

	raster::iterator img_it;
	for( img_it = imagination.begin(); img_it != imagination.end(); ++img_it ) {
		size_type x = img_it.x()/x_enlargement;
		size_type y = img_it.y()/y_enlargement;
		if( img_it.x()%x_enlargement == x_enlargement-1 && bounds.horiz_dividual(y,x) ||
			img_it.y()%y_enlargement == y_enlargement-1 && bounds.vert_dividual(x,y) )
		{
			*img_it = bound_color;
		} else {
			*img_it = bgrd(x,y);
		}
	}
}

} //namespace img

#endif //_imagine_h_
